var Protocol = require("../../Controls/Protocol")
import Dialog from '../../miniprogram_npm/vant-weapp/dialog/dialog.js'
const app = getApp();

var data = 
{
  balance:"0.0",
  putvalue:0,
}

var putall = function()
{
  this.setData({ putvalue: parseFloat(this.data.balance)})
}

var btnExtractIvk = function()
{
  if (!app.globalData.enableEncashment)
  {
    Dialog.alert({ message: "平台尚未开启取现", zIndex: 9999 });
    return;
  }

  if (this.data.putvalue < 5)
  {
    Dialog.alert({ message: "提现最低额度5元", zIndex: 9999 });
    return;
  }
  const value = parseFloat(this.data.putvalue);
  if(!value)
  {
    return;
  }
  Protocol.encashment(value.toString());
}

var onLoad = function()
{
  this.setData({balance:app.globalData.credit.balance});
}

function valueInput(e)
{
  this.setData({ putvalue: e.detail.value});
}

var options = 
{
  data,
  putall,
  btnExtractIvk,
  onLoad,
  valueInput,
}

Page(options)